package com.itbaizhan.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

//Element:元素对象
public class Demo4 {
    /*String text():获取元素包含的纯文本
    * String html():获取元素包含的带标签的文本
    * String attr(String attributeKey): 获取元素的属性值*/

    public static void main(String[] args) throws IOException {
        String path = Demo4.class.getClassLoader().getResource("com/itbaizhan/xsd/student.xml").getPath();
        //获得Document对象
        Document document = Jsoup.parse(new File(path),"utf-8");

        //使用cs选择器获得元素
        Elements elements = document.select("#baizhan_0001");
        //Elements 是一个集合
        Element elements1 = elements.get(0);
        System.out.println(elements1.text());
        System.out.println("----------");
        System.out.println(elements1.html());
        System.out.println("------------");
        System.out.println(elements1.attr("id"));
    }
}
